package com.bw.sort;

import static jdk.nashorn.internal.objects.Global.print;

public class Speediness {
        /**
         * 快速排序
         */
        public static  void sort(int[] arr, int low,int high){
        int l=low;
        int h=high;
        int povit=arr[low];

         while(l<h)
        {
        while(l<h&&arr[h]>=povit)
        h--;
        if(l<h){
        int temp=arr[h];
        arr[h]=arr[l];
        arr[l]=temp;
        l++;
        }

        while(l<h&&arr[l]<=povit)
        l++;

        if(l<h){
        int temp=arr[h];
        arr[h]=arr[l];
        arr[l]=temp;
        h--;
        }
        print(arr);
        System.out.print("l="+(l+1)+"h="+(h+1)+"povit="+povit+"\n");
        if(l>low)sort(arr,low,l-1);
        if(h<high)sort(arr,l+1,high);
        }
    }

    public static void main(String[] args) {
            int arr[]={1,6,25,7,8,9,3,4,15,16};
            int low = 0;
            int high = arr.length-1;
        System.out.println(low+"--"+high);
        Speediness.sort(arr,low,high);
    }
}
